const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const path = require("path");
const cesiumSource = "./node_modules/cesium/Source";
const cesiumWorks = "../Build/Cesium/Workers";
module.exports = {
  outputDir: 'dist', //打包后的文件夹路径
  // publicPath:'/webapp/nucleardamagerule', // 虚拟路径
  publicPath: "./",
  devServer: {
    open: process.platform === "darwin", // 查询操作系统是不是mac
    host: "0.0.0.0",
    port: 8080,
    https: false,
    hotOnly: false,
    proxy: {
      '/api': {
        target: 'http://jsonplaceholder.typicode.com', // 目标服务地址
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/api': '' //把api 替换成 空
        }
      }
      // 可以写多个路有路径进行转发
    }
  },
  configureWebpack: {
    resolve: {
      alias: {
        "@": path.resolve("src"),
        "cesium": path.resolve(__dirname, cesiumSource)
      }
    },
    plugins: [
      new CopyWebpackPlugin([
        {
          from: path.join(cesiumSource, cesiumWorks),
          to: "Workers"
        }
      ]),
      new CopyWebpackPlugin([
        {
          from: path.join(cesiumSource, "Assets"),
          to: "Assets"
        }
      ]),
      new CopyWebpackPlugin([
        {
          from: path.join(cesiumSource, "Widgets"),
          to: "Widgets"
        }
      ]),
      new CopyWebpackPlugin([
        {
          from: path.join(cesiumSource, "ThirdParty"),
          to: "ThirdParty"
        }
      ]),



      new webpack.DefinePlugin({
        CESIUM_BASE_URL: JSON.stringify("./")
      })
    ],
    module: {
      // unknownContextRegExp: /^.\/.*$/,
      unknownContextCritical: false,
      wrappedContextCritical: false
    }
  }
}